<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="div1">div1</div>
		<div id="div2">div2</div>
		<div id="div3">div3</div>
		<div class="cls1">div4</div>
		<div class="cls1">div5</div>

		<input name="userName">

		<script>
			// 获取所有的div标签
			var divs = document.getElementsByTagName("div");
			// alert(divs.length);
			// 获取所以的className
			var cls = document.getElementsByClassName("cls1");
			// alert(cls.length);
			//获取所有name为userName的div
			var divName = document.getElementsByName("userName");
			alert(divName.length);
		</script>

	</body>
</html>
